package RmqManager

import (
	"context"
	"deepgox-go-admin/Infrastructures/Rocketmq/Producer"
	"deepgox-go-admin/Models/Manager"
	"deepgox-go-admin/Settings"
	"encoding/json"
	"fmt"
	"github.com/apache/rocketmq-client-go/v2/primitive"
	"time"
)

// RegModelHandler 管理员注册服务模型
type RegModelHandler struct {
	Manager.AddModelHandler
}

func (managerModel *RegModelHandler) RmqAddManagerDao() error {
	prod, err := Producer.Init(Settings.Conf.RocketmqConfig)
	if err != nil {
		panic("生成producer失败")
	}
	jsonData, err := json.Marshal(managerModel)

	res, err := prod.SendSync(context.Background(), primitive.NewMessage("manager_topic", jsonData))
	if err != nil {
		panic("消息发送失败" + err.Error())
	}
	nowStr := time.Now().Format("2006-01-02 15:04:05")
	fmt.Printf("%s: 消息: %s发送成功 \n", nowStr, res.String())
	return err
}
